package com.example.fastjson;

import com.alibaba.fastjson.JSON;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Created at 2017/8/19 19:26
 *
 * @author gongweixin
 */
public class Main {

    @Test
    public void testToString() {
        assertEquals("{\"a\":0}", JSON.toJSONString(new Bean()));
    }

    @Test
    public void testToBean() {
        assertEquals(new Bean(), JSON.parseObject("{\"a\":0}", Bean.class));
    }

    static class Bean {
        private int a;

        public int getA() {
            return a;
        }

        public void setA(int a) {
            this.a = a;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Bean bean = (Bean) o;

            return a == bean.a;

        }
    }
}
